package com.yisoo.ubag.app.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yisoo.ubag.app.entity.CouponEntity;
import com.yisoo.ubag.app.service.CouponService;
import com.yisoo.common.utils.PageUtils;
import com.yisoo.common.utils.R;



/**
 * 
 *
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-04-30 15:49:30
 */
@RestController
@RequestMapping("app/coupon")
public class CouponController {
    @Autowired
    private CouponService couponService;



    @GetMapping("/get/by/uid/{userid}")
    public R getByUid(@PathVariable("userid") String uid){
        return couponService.getAllWithNewUser(uid);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("app:coupon:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{couponId}")
    //@RequiresPermissions("app:coupon:info")
    public R info(@PathVariable("couponId") Integer couponId){
		CouponEntity coupon = couponService.getById(couponId);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("app:coupon:save")
    public R save(@RequestBody CouponEntity coupon){
		couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("app:coupon:update")
    public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("app:coupon:delete")
    public R delete(@RequestBody Integer[] couponIds){
		couponService.removeByIds(Arrays.asList(couponIds));

        return R.ok();
    }

}
